/**
 * Created by kim on 2015/9/25.
 */
define('jquery', [], function () {
  return jQuery;
});

require.config({
  baseUrl: HB.env === 'demo' ? HB.localStaticPrefix : HB.staticPrefix,
  map: {
    '*': {
      'css': 'vendor/require-css.min'
    }
  },
  shim: {
    'jquery': {exports: '$'},
    'datepicker': {
      deps: ['css!vendor/datepicker/css/jquery-ui.css', 'migrate']
    },
    'tips': {
      deps: ['css!vendor/poshytip/hb-tips/hb-tips.css']
    },
    'jcrop': {
      deps: ['css!vendor/jcrop/css/jquery.Jcrop.min.css']
    },
    'upload': {
      deps: ['css!vendor/uploadify/uploadify.css']
    }
  },
  paths: {
    'projects': (HB.env === 'local' || HB.env === 'demo' ? HB.localStaticPrefix : HB.staticPrefix) + 'projects',
    'jquery': 'vendor/jquery-1.11.0.min',
    'migrate': 'vendor/jquery-migrate-1.2.1.min',
    'template': 'vendor/artTemplate/template',
    'autocomplete': 'vendor/autocomplete/jquery.autocomplete.min',
    'datepicker': 'vendor/datepicker/js/jquery-ui-datepicker',
    'tips': 'vendor/poshytip/jquery.poshytip.min',
    'jcrop': 'vendor/jcrop/js/jquery.Jcrop.min',
    'upload': 'vendor/uploadify/jquery.uploadify.min',
    'form-validate': 'vendor/validation/jquery.validate',
    'spin': 'vendor/spin.min'
  }
});

//加载页面js模块
$(document).ready(function () {
  $('script').each(function () {
    var module = $(this).attr('data-hb-js');
    //如果不是本地开发环境，则加载min文件
    if (module) {
      if (HB.env === 'prod' || HB.env === 'test') {
        module += ".min";
      } else {
        //如果是本地开发环境，则读取本地的文件（去掉版本号目录）
        module = module.replace(/\d+./g, '');
      }
      //初始化参数
      var args = {};
      var initArgs = $(this).attr("data-init-args");
      if (initArgs) {
        var p1 = initArgs.split(',');
        $(p1).each(function (idx, item) {
          var p2 = item.split('=');
          args[p2[0]] = p2[1];
        });
      }
      require([module], function (module) {
        module.init(args);
      });
    }
  });
});